<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>java基础：map接口 | haijd</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  
  <meta name="keywords" content="Java基础" />
  
  
  
  
  <meta name="description" content="Java中的Map接口使用概述">
<meta name="keywords" content="Java基础">
<meta property="og:type" content="article">
<meta property="og:title" content="Java基础：Map接口">
<meta property="og:url" content="http://www.hais2.com/2017/06/20/Java基础：Map接口/index.html">
<meta property="og:site_name" content="haijd">
<meta property="og:description" content="Java中的Map接口使用概述">
<meta property="og:locale" content="default">
<meta property="og:image" content="http://ww1.sinaimg.cn/large/c55a7aeely1fmbwbz5s71j20et08cjra.jpg">
<meta property="og:updated_time" content="2017-12-17T14:49:40.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Java基础：Map接口">
<meta name="twitter:description" content="Java中的Map接口使用概述">
<meta name="twitter:image" content="http://ww1.sinaimg.cn/large/c55a7aeely1fmbwbz5s71j20et08cjra.jpg">
  
    <link rel="alternate" href="/atom.xml" title="haijd" type="application/atom+xml">
  
  <link rel="icon" href="/css/images/favicon.ico">
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link href="https://fonts.googleapis.com/css?family=Open+Sans|Montserrat:700" rel="stylesheet" type="text/css">
  <link href="https://fonts.googleapis.com/css?family=Roboto:400,300,300italic,400italic" rel="stylesheet" type="text/css">
  <link href="//cdn.bootcss.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet">
  <style type="text/css">
    @font-face{font-family:futura-pt;src:url(https://use.typekit.net/af/9749f0/00000000000000000001008f/27/l?subset_id=2&fvd=n5) format("woff2");font-weight:500;font-style:normal;}
    @font-face{font-family:futura-pt;src:url(https://use.typekit.net/af/90cf9f/000000000000000000010091/27/l?subset_id=2&fvd=n7) format("woff2");font-weight:500;font-style:normal;}
    @font-face{font-family:futura-pt;src:url(https://use.typekit.net/af/8a5494/000000000000000000013365/27/l?subset_id=2&fvd=n4) format("woff2");font-weight:lighter;font-style:normal;}
    @font-face{font-family:futura-pt;src:url(https://use.typekit.net/af/d337d8/000000000000000000010095/27/l?subset_id=2&fvd=i4) format("woff2");font-weight:400;font-style:italic;}</style>
    
  <link rel="stylesheet" id="athemes-headings-fonts-css" href="//fonts.googleapis.com/css?family=Yanone+Kaffeesatz%3A200%2C300%2C400%2C700&amp;ver=4.6.1" type="text/css" media="all">
  <link rel="stylesheet" href="/css/style.css">

  <script src="/js/jquery-3.1.1.min.js"></script>

  <!-- Bootstrap core CSS -->
  <link rel="stylesheet" href="/css/bootstrap.css" >
  <link rel="stylesheet" href="/css/hiero.css" >
  <link rel="stylesheet" href="/css/glyphs.css" >
  
    <link rel="stylesheet" href="/css/vdonate.css" >
  

</head>

<script>
var themeMenus = {};

  themeMenus["/"] = "Home"; 

  themeMenus["/archives"] = "Archives"; 

  themeMenus["/categories"] = "Categories"; 

  themeMenus["/tags"] = "Tags"; 

  themeMenus["/about"] = "About"; 

</script>


  <body data-spy="scroll" data-target="#toc" data-offset="50">


  <header id="allheader" class="site-header" role="banner">
  <div class="clearfix container">
      <div class="site-branding">

          <h1 class="site-title">
            
              <a href="/" title="haijd" rel="home"> haijd </a>
            
          </h1>

          
            <div class="site-description">Stay Hungry,Stay Foolish</div>
          
            
          <nav id="main-navigation" class="main-navigation" role="navigation">
            <a class="nav-open">Menu</a>
            <a class="nav-close">Close</a>
            <div class="clearfix sf-menu">

              <ul id="main-nav" class="nmenu sf-js-enabled">
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663"> <a class="" href="/">Home</a> </li>
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663"> <a class="" href="/archives">Archives</a> </li>
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663"> <a class="" href="/categories">Categories</a> </li>
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663"> <a class="" href="/tags">Tags</a> </li>
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663"> <a class="" href="/about">About</a> </li>
                    
              </ul>
            </div>
          </nav>


      </div>
  </div>
</header>




  <div id="container">
    <div id="wrap">
            
      <div id="content" class="outer">
        
          <section id="main" style="float:none;"><article id="post-Java基础：Map接口" style="width: 66%; float:left;" class="article article-type-post" itemscope itemprop="blogPost" >
  <div id="articleInner" class="clearfix post-1016 post type-post status-publish format-standard has-post-thumbnail hentry category-template-2 category-uncategorized tag-codex tag-edge-case tag-featured-image tag-image tag-template">
    
<div class="article-gallery">
  <div class="article-gallery-photos">
    
      <a class="article-gallery-img fancybox" href="http://ww1.sinaimg.cn/large/c55a7aeely1fmbwbz5s71j20et08cjra.jpg" rel="gallery_cjie4nahr004h3swazc8g8vlu">
        <img src="http://ww1.sinaimg.cn/large/c55a7aeely1fmbwbz5s71j20et08cjra.jpg" itemprop="image">
      </a>
    
  </div>
</div>

    
      <header class="article-header">
        
  
    <h1 class="thumb" class="article-title" itemprop="name">
      Java基础：Map接口
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	Posted on <a href="/2017/06/20/Java基础：Map接口/" class="article-date">
	  <time datetime="2017-06-20T14:13:42.000Z" itemprop="datePublished">June 20, 2017</time>
	</a>

      
	<span id="busuanzi_container_page_pv">
	  本文总阅读量<span id="busuanzi_value_page_pv"></span>次
	</span>

    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <!-- TOC -->
<ul>
<li><a href="#map接口">Map接口</a></li>
<li><a href="#map接口中的常用方法">Map接口中的常用方法</a></li>
<li><a href="#map集合遍历keyset">Map集合遍历(keySet)</a></li>
<li><a href="#map集合entry对象">Map集合Entry对象</a></li>
<li><a href="#map集合遍历entryset方法">Map集合遍历(entrySet方法)</a></li>
<li><a href="#hashmap集合存储自定义对象">HashMap集合存储自定义对象</a></li>
<li><a href="#linkedhashmap">LinkedHashMap</a></li>
</ul>
<!-- /TOC -->
<h3 id="Map接口"><a href="#Map接口" class="headerlink" title="Map接口"></a>Map接口</h3><ul>
<li>Map接口概述:<ul>
<li>Map中存储元素是成对存在的，每一个元素都包含键和值(key、value)。</li>
<li>Map集合不能批量添加，只能执行单个添加操作。</li>
<li>Map集合中的<code>key</code>是不能重复的，但是<code>value</code>可以重复，每个键只能对应一个值。</li>
<li>Map下的主要实现类：<code>HashMap</code>、<code>LinkedHashMap</code></li>
</ul>
</li>
</ul>
<a id="more"></a>
<h3 id="Map接口中的常用方法"><a href="#Map接口中的常用方法" class="headerlink" title="Map接口中的常用方法"></a>Map接口中的常用方法</h3><ul>
<li><code>public V put(K key, V value)</code> ：存储键值对</li>
<li><code>public void putAll(Map&lt;? extends K, ? extends V&gt; m)</code> :添加一个相同类型的Map(注意限定符约束)</li>
<li><p>查看源码可以知道，无论是put还是putAll最终调用的都是<code>putVal</code>这个方法(putAll也是循环调用的该方法)</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//可以看到第一个参数是一个hash</span></span><br><span class="line"><span class="function"><span class="keyword">final</span> V <span class="title">putVal</span><span class="params">(<span class="keyword">int</span> hash, K key, V value, <span class="keyword">boolean</span> onlyIfAbsent,<span class="keyword">boolean</span> evict)</span></span>&#123;&#125;</span><br><span class="line"><span class="comment">//从这里可以看出来，HashMap在存储的时候会对key进行hash操作，在putVal方法中对hash进行判断，用来判重</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> V <span class="title">put</span><span class="params">(K key, V value)</span> </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> putVal(hash(key), key, value, <span class="keyword">false</span>, <span class="keyword">true</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p><code>public V get(Object key)</code> ：根据key获取value</p>
</li>
<li><p><code>public V getOrDefault(Object key, V defaultValue)</code> ：根据key获取value，并且传递一个默认的value，当该key的时候，就返回这个传过来的默认的value，这是JDK8中新扩展的方法。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> V <span class="title">get</span><span class="params">(Object key)</span> </span>&#123;</span><br><span class="line">        Node&lt;K,V&gt; e;</span><br><span class="line">        <span class="keyword">return</span> (e = getNode(hash(key), key)) == <span class="keyword">null</span> ? <span class="keyword">null</span> : e.value;</span><br><span class="line">    &#125;</span><br><span class="line"><span class="comment">// Overrides of JDK8 Map extension methods</span></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> V <span class="title">getOrDefault</span><span class="params">(Object key, V defaultValue)</span> </span>&#123;</span><br><span class="line">        Node&lt;K,V&gt; e;</span><br><span class="line">        <span class="keyword">return</span> (e = getNode(hash(key), key)) == <span class="keyword">null</span> ? defaultValue : e.value;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p><code>public V remove(Object key)</code> ：根据key删除集合中的键值对</p>
</li>
<li><code>public boolean remove(Object key, Object value)</code> :根据key、value的值删除集合中的键值对，键和值都匹配上才删除。</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">function</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    Map&lt;String, Integer&gt; map=<span class="keyword">new</span> HashMap&lt;String,Integer&gt;();</span><br><span class="line">    map.put(<span class="string">"a"</span>, <span class="number">1</span>);</span><br><span class="line">    map.put(<span class="string">"b"</span>, <span class="number">2</span>);</span><br><span class="line">    System.out.println(map);  <span class="comment">// &#123;a=1, b=2&#125;</span></span><br><span class="line">    Integer integer=map.get(<span class="string">"a"</span>);  </span><br><span class="line">    System.out.println(integer);   <span class="comment">//1</span></span><br><span class="line">    Integer value=map.remove(<span class="string">"a"</span>);</span><br><span class="line">    System.out.println(value);     <span class="comment">//1</span></span><br><span class="line">    <span class="keyword">boolean</span> success=map.remove(<span class="string">"b"</span>, <span class="number">2</span>);</span><br><span class="line">    System.out.println(success);  <span class="comment">//true</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="Map集合遍历-keySet"><a href="#Map集合遍历-keySet" class="headerlink" title="Map集合遍历(keySet)"></a>Map集合遍历(keySet)</h3><ul>
<li>首先获取Map集合中所有的键，<code>keySet()</code>方法返回一个Set集合存储所有的键</li>
<li>遍历返回的Set，调用<code>get(key)</code>方法获取对应的值</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">function</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    Map&lt;String, Integer&gt; map=<span class="keyword">new</span> HashMap&lt;String,Integer&gt;();</span><br><span class="line">    map.put(<span class="string">"a"</span>, <span class="number">1</span>);</span><br><span class="line">    map.put(<span class="string">"b"</span>, <span class="number">2</span>);</span><br><span class="line">    Set&lt;String&gt; keys= map.keySet();</span><br><span class="line">    <span class="keyword">for</span> (String key : keys) &#123;</span><br><span class="line">		Integer value=map.get(key);</span><br><span class="line">		System.out.println(value);   <span class="comment">//1 2</span></span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	<span class="comment">//Iterator迭代器方式</span></span><br><span class="line">	Iterator&lt;String&gt; iterator=keys.iterator();</span><br><span class="line">    <span class="keyword">while</span> (iterator.hasNext()) &#123;</span><br><span class="line">		String key=iterator.next();</span><br><span class="line">		Integer value=map.get(key);</span><br><span class="line">		System.out.println(value);</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="Map集合Entry对象"><a href="#Map集合Entry对象" class="headerlink" title="Map集合Entry对象"></a>Map集合Entry对象</h3><ul>
<li>Map接口中有一个嵌套的接口<code>Entry&lt;K,V&gt;</code>，它将键值对的对应关系封装成了键值对对象</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">interface</span> <span class="title">Entry</span>&lt;<span class="title">K</span>,<span class="title">V</span>&gt; </span>&#123;</span><br><span class="line">	<span class="function">K <span class="title">getKey</span><span class="params">()</span></span>;</span><br><span class="line">	<span class="function">V <span class="title">getValue</span><span class="params">()</span></span>;</span><br><span class="line">	<span class="function">V <span class="title">setValue</span><span class="params">(V value)</span></span>;</span><br><span class="line">	<span class="function"><span class="keyword">boolean</span> <span class="title">equals</span><span class="params">(Object o)</span></span>;</span><br><span class="line">	<span class="function"><span class="keyword">int</span> <span class="title">hashCode</span><span class="params">()</span></span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<ul>
<li>在Map接口中有一个方法<code>Set&lt;Map.Entry&lt;K, V&gt;&gt; entrySet();</code> <code>HashMap</code>重写了这个方法，返回Map集合中所有的Entry(键值对)对象。<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> Set&lt;Map.Entry&lt;K,V&gt;&gt; entrySet() &#123;</span><br><span class="line">    Set&lt;Map.Entry&lt;K,V&gt;&gt; es;</span><br><span class="line">    <span class="keyword">return</span> (es = entrySet) == <span class="keyword">null</span> ? (entrySet = <span class="keyword">new</span> EntrySet()) : es;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
</ul>
<h3 id="Map集合遍历-entrySet方法"><a href="#Map集合遍历-entrySet方法" class="headerlink" title="Map集合遍历(entrySet方法)"></a>Map集合遍历(entrySet方法)</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">function</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    Map&lt;String, Integer&gt; map=<span class="keyword">new</span> HashMap&lt;String,Integer&gt;();</span><br><span class="line">    map.put(<span class="string">"a"</span>, <span class="number">1</span>);</span><br><span class="line">    map.put(<span class="string">"b"</span>, <span class="number">2</span>);</span><br><span class="line">    <span class="comment">//获取map的键值对Set集合</span></span><br><span class="line">    Set&lt;Map.Entry&lt;String,Integer&gt;&gt; set=map.entrySet();</span><br><span class="line">	<span class="comment">//获取该Set的迭代器对象</span></span><br><span class="line">    Iterator&lt;Map.Entry&lt;String, Integer&gt;&gt; iterator=set.iterator();</span><br><span class="line">    <span class="keyword">while</span> (iterator.hasNext()) &#123;</span><br><span class="line">		Map.Entry&lt;String, Integer&gt; entry=iterator.next();</span><br><span class="line">		<span class="comment">//调用Entry对象的方法获取键和值</span></span><br><span class="line">		String key=entry.getKey();</span><br><span class="line">		Integer value=entry.getValue();</span><br><span class="line">		System.out.println(<span class="string">"Key:"</span>+key+<span class="string">"---------"</span>+<span class="string">"Value:"</span>+value);  </span><br><span class="line">		<span class="comment">// 输出：Key:a---------Value:1  Key:b---------Value:2</span></span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	<span class="comment">//foreach</span></span><br><span class="line">	<span class="keyword">for</span> (Map.Entry&lt;String, Integer&gt; entry : set) &#123;</span><br><span class="line">        System.out.println(<span class="string">"Key:"</span>+entry.getKey()+<span class="string">"---------"</span>+<span class="string">"Value:"</span>+entry.getValue());</span><br><span class="line">		<span class="comment">// 输出：Key:a---------Value:1  Key:b---------Value:2</span></span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="HashMap集合存储自定义对象"><a href="#HashMap集合存储自定义对象" class="headerlink" title="HashMap集合存储自定义对象"></a>HashMap集合存储自定义对象</h3><ul>
<li><code>HashMap</code>集合的key、value值都可以是Object类型的，也就是可以存储任意类型的对象。</li>
<li>key为自定义对象时：<ul>
<li>因为Map类型的数据在存储时，会对key进行哈希，如果是自定义对象还会调用<code>Object</code>对象的<code>equals</code>方法比较key是否重复。</li>
<li>默认的<code>Object</code>对象的<code>equals</code>方法其实调用的是<code>==</code>比较的，也就是比较的对象的地址。所以当自定义对象作为Map的键时，应该重写Object的equals方法，例如比较对象中属性值的不同。</li>
</ul>
</li>
<li>value为自定义对象时：<ul>
<li>因为Map存储时判断的时键是否重复，所以value为自定义对象时，可以没有特殊的处理。</li>
</ul>
</li>
</ul>
<h3 id="LinkedHashMap"><a href="#LinkedHashMap" class="headerlink" title="LinkedHashMap"></a>LinkedHashMap</h3><ul>
<li><code>LinkedHashMap</code>和<code>HashMap</code>基本一致，<code>LinkedHashMap</code>的特定就是可以保证迭代的顺序和插入的顺序一致。<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">function</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    LinkedHashMap&lt;String, Integer&gt; map=<span class="keyword">new</span> LinkedHashMap&lt;String,Integer&gt;();</span><br><span class="line">    map.put(<span class="string">"a"</span>, <span class="number">1</span>);</span><br><span class="line">    map.put(<span class="string">"b"</span>, <span class="number">2</span>);</span><br><span class="line">    System.out.println(map);  <span class="comment">//输出：&#123;a=1, b=2&#125;</span></span><br><span class="line">    Set&lt;String&gt; set=map.keySet();</span><br><span class="line">    <span class="keyword">for</span> (String key : set) &#123;</span><br><span class="line">		System.out.println(<span class="string">"Value:"</span>+map.get(key));  <span class="comment">//输出：Value:1   Value:2</span></span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
</ul>

      
    </div>
    <footer class="entry-meta entry-footer">
      
	<span class="ico-folder"></span>
    <a class="article-category-link" href="/categories/Java/">Java</a>

      
  <span class="ico-tags"></span>
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Java基础/">Java基础</a></li></ul>

      
        <div id="donation_div"></div>

<script src="/js/vdonate.js"></script>
<script>
var a = new Donate({
  title: '如果觉得我的文章对您有用，请随意打赏。您的支持将鼓励我继续创作!', // 可选参数，打赏标题
  btnText: 'Donate', // 可选参数，打赏按钮文字
  el: document.getElementById('donation_div'),
  wechatImage: '/css/images/wechatPay.png',
  alipayImage: '/css/images/alipay.jpg'
});
</script>
      

      
        
	<section id="comments" class="comment">
	  <div id="disqus_thread">
	  <noscript>Please enable JavaScript to view the <a href="//disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
	  </div>
	</section>

	<script type="text/javascript">
	var disqus_shortname = 'haijdblog';
	(function(){
	  var dsq = document.createElement('script');
	  dsq.type = 'text/javascript';
	  dsq.async = true;
	  dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
	  (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
	}());
	(function(){
	  var dsq = document.createElement('script');
	  dsq.type = 'text/javascript';
	  dsq.async = true;
	  dsq.src = '//' + disqus_shortname + '.disqus.com/count.js';
	  (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
	}());
	</script>


      
    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2017/08/08/GO环境安装部署/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          GO环境安装部署
        
      </div>
    </a>
  
  
    <a href="/2017/06/16/Java基础：Set接口/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">Java基础：Set接口</div>
    </a>
  
</nav>

  
</article>

<!-- Table of Contents -->

  <aside id="sidebar">
    <div id="toc" class="toc-article">
    <strong class="toc-title">Contents</strong>
    
      <ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#Map接口"><span class="nav-number">1.</span> <span class="nav-text">Map接口</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Map接口中的常用方法"><span class="nav-number">2.</span> <span class="nav-text">Map接口中的常用方法</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Map集合遍历-keySet"><span class="nav-number">3.</span> <span class="nav-text">Map集合遍历(keySet)</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Map集合Entry对象"><span class="nav-number">4.</span> <span class="nav-text">Map集合Entry对象</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Map集合遍历-entrySet方法"><span class="nav-number">5.</span> <span class="nav-text">Map集合遍历(entrySet方法)</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#HashMap集合存储自定义对象"><span class="nav-number">6.</span> <span class="nav-text">HashMap集合存储自定义对象</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#LinkedHashMap"><span class="nav-number">7.</span> <span class="nav-text">LinkedHashMap</span></a></li></ol>
    
    </div>
  </aside>
</section>
        
      </div>
      <footer id="footer" class="site-footer">
  

  <div class="clearfix container">
      <div class="site-info">
	      &copy; 2018 haijd All Rights Reserved.
          
            <span id="busuanzi_container_site_uv">
              本站访客数<span id="busuanzi_value_site_uv"></span>人次  
              本站总访问量<span id="busuanzi_value_site_pv"></span>次
            </span>
          
      </div>
      <div class="site-credit">
        Theme by <a href="https://github.com/iTimeTraveler/hexo-theme-hiero" target="_blank">hiero</a>
      </div>
  </div>
</footer>


<!-- min height -->

<script>
    var contentdiv = document.getElementById("content");

    contentdiv.style.minHeight = document.body.offsetHeight - document.getElementById("allheader").offsetHeight - document.getElementById("footer").offsetHeight + "px";
</script>
    </div>
    <!-- <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
    <a href="/categories" class="mobile-nav-link">Categories</a>
  
    <a href="/tags" class="mobile-nav-link">Tags</a>
  
    <a href="/about" class="mobile-nav-link">About</a>
  
</nav> -->
    

<!-- mathjax config similar to math.stackexchange -->

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    tex2jax: {
      inlineMath: [ ['$','$'], ["\\(","\\)"] ],
      processEscapes: true
    }
  });
</script>

<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
      tex2jax: {
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
    });
</script>

<script type="text/x-mathjax-config">
    MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for(i=0; i < all.length; i += 1) {
            all[i].SourceElement().parentNode.className += ' has-jax';
        }
    });
</script>

<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>


  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css">
  <script src="/fancybox/jquery.fancybox.pack.js"></script>


<script src="/js/scripts.js"></script>
<script src="/js/bootstrap.js"></script>
<script src="/js/main.js"></script>








	<script async src="//dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js">
	</script>






  </div>

  <a id="rocket" href="#top" class=""></a>
  <script type="text/javascript" src="/js/totop.js" async=""></script>
</body>
</html>
